<style lang="less" scoped>
  .mdiv {

  .mButton {
    margin-bottom: 10px;
  }

  .mButtonLeft {
    margin-left: 10px;
    float: left;
  }

  .mButtonRight {
    margin-right: 10px;
    float: right;
  }

    .f-w50 {
      size: large;
    }
  }

</style>
<template>
  <section>
    <div class="mdiv">
      <el-tabs style="height: 100%" v-model="allSms">
        <el-tab-pane label="短信群发" name="sendSmsTab" style="height: 100%">
          <search-bar more-display>
            <el-row>
              <el-col :span="8">
                <el-form-item label="群发名称">
                  <el-input  placeholder="请输入群发名称" v-model="condition.LIKE_title"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="短信模板">
                  <el-select v-model="condition.EQ_templateAliId" placeholder="请选择模板类型">
                    <el-option
                      v-for="item in $store.getters.SMS_TEMPLATE_TYPE"
                      :label="item.cnDictValname"
                      :key="item.dictVal"
                      :value="item.dictVal">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="短信状态">
                  <el-select v-model="condition.EQ_status" placeholder="请选择短信状态">
                    <el-option
                      v-for="item in $store.getters.SMS_SEND_STATUS"
                      :label="item.cnDictValname"
                      :key="item.dictVal"
                      :value="item.dictVal">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="申请日期">
                  <el-date-picker type="daterange" placeholder="请选择申请日期"
                                  v-model="condition.createDate"></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="发送方式">
                  <el-select v-model="condition.EQ_sendType" placeholder="请选择发送方式">
                    <el-option
                      v-for="item in $store.getters.SMS_SEND_TYPE"
                      :label="item.cnDictValname"
                      :key="item.dictVal"
                      :value="item.dictVal">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </search-bar>
          <el-col :span="24" class="mButton">
            <el-button type="primary" @click="addSms" style="margin-left: 10px">新建群发</el-button>
            <el-button type="primary" @click="resetCondition" style="float: right;margin-left: 10px">重置</el-button>
            <el-button type="primary" @click="searchSMs" style="float: right">查询</el-button>
          </el-col>
          <el-table :data="smsTableData" highlight-current-row border max-height="600"
                    @selection-change="smsTableSelsChange" v-loading="smsListLoading" style="width:100%">
            <el-table-column type="index" label="序号" width="60"></el-table-column>
            <el-table-column prop="title" label="群发名称" width="150" align="center"></el-table-column>
            <el-table-column prop="createDate" label="申请日期" width="130" align="center">
              <template slot-scope="scope">
                {{scope.row.createDate.substring(0,10)}}
              </template>
            </el-table-column>
            <el-table-column prop="sendTime" label="发送时间" width="180" align="center"></el-table-column>
            <el-table-column prop="templateName" label="短信模板" width="180" align="center"></el-table-column>
            <el-table-column prop="templateContent" label="短信模板内容" width="220" align="center"></el-table-column>
            <el-table-column prop="statusName" label="状态" width="150" align="center"></el-table-column>
            <el-table-column prop="sendTypeName" label="发送方式" width="100" align="center"></el-table-column>
            <el-table-column  label="发送对象" width="100" align="center">
              <template slot-scope="scope">
                <label v-if="scope.row.sendToStmPersonal === 111002001">系统用户</label>
                <label v-if="scope.row.sendToStmPersonal === 111002002">非系统用户</label>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="350" fixed="right">
              <template slot-scope="scope">
                <el-button type="primary"   v-if="scope.row.sendToStmPersonal === 111002001" @click="acceptPersonFormVisiable(scope.row)">群发对象</el-button>
                <el-button type="primary"   v-if="scope.row.sendToStmPersonal === 111002002" @click="importAcceptPhones(scope.row)">导入群发电话</el-button>
                <label v-if="scope.row.status === 114008001">
                  <el-button type="primary" @click="confirm(scope.row)">确认审核</el-button>
                  <el-button type="primary" @click="editGroupSendPlan(scope.row)">编辑</el-button>
                  <el-button type="danger" @click="deleteGroupSendPlan(scope.row)">删除</el-button>
                </label>
                <label v-if="scope.row.status === 114008002">
                  <el-button type="primary" @click="testSendSms(scope.row)">效果</el-button>
                  <el-button type="warning" @click="cancleConfirm(scope.row)">撤销</el-button>
                </label>
                <label v-if="scope.row.sendTypeName === '手动发送' && scope.row.status === 114008002">
                  <el-button type="success" @click="groupSendSms(scope.row)">发送</el-button>
                </label>
              </template>
            </el-table-column>
          </el-table>
          <!--工具条-->
          <el-col :span="24" class="toolbar">
            <el-pagination
              :current-page="currentPage"
              :page-size="pageSize"
              @size-change="handlePageSizeChange"
              @current-change="handleCurrentPageChange"
              layout="total,sizes,prev, pager, next, jumper"
              :total="total" style="float: right">
            </el-pagination>
          </el-col>
        </el-tab-pane>
        <el-tab-pane label="已发短信" name="alreadySendSmsTab" style="height: 100%">
          <search-bar>
            <el-row>
              <el-col :span="8">
                <el-form-item label="发送日期">
                  <el-date-picker type="daterange" placeholder="请选择发送日期"
                                  v-model="hisCondition.fixedTime"></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="手机号码">
                  <el-input  placeholder="请输入客户手机" v-model="hisCondition.LIKE_phone"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="接收状态">
                  <el-select v-model="hisCondition.EQ_sendResult" placeholder="请选择接收状态">
                    <el-option
                      v-for="item in $store.getters.INDICATOR"
                      :label="item.cnDictValname === '是'?'成功':'失败'"
                      :key="item.dictVal"
                      :value="item.dictVal">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </search-bar>
          <el-col :span="24">
            <el-button type="primary" class="mButtonRight mButton" @click="resetHisCondition">重置</el-button>
            <el-button type="primary" class="mButtonRight mButton" @click="searchHisSendSms">查询</el-button>
            <el-button type="primary" class="mButtonLeft mButton" @click="exportSendSms">导出数据</el-button>
          </el-col>
          <el-table :data="hisSendSmsTableData" border max-height="600">
            <el-table-column type="index" label="序号" width="100px"></el-table-column>
            <el-table-column prop="fixedTime" label="发送时间" width="200px"></el-table-column>
            <el-table-column prop="sendResult" label="发送状态" width="120px">
              <template slot-scope="scope">
                <label v-if="scope.row.sendResult === 111002001">发送成功</label>
                <label v-if="scope.row.sendResult === 111002002">发送失败</label>
              </template>
            </el-table-column>
            <el-table-column prop="content" label="短信内容" width="930"></el-table-column>
            <el-table-column prop="phone" label="手机号码" width="150px"></el-table-column>
            <el-table-column prop="sendResultDetail" label="接收状态" width="150px">
              <template slot-scope="scope">
                <label v-if="scope.row.sendResult === 111002001">{{scope.row.sendResultDetail}}</label>
                <label v-if="scope.row.sendResult === 111002002"
                       style="color: red">{{scope.row.sendResultDetail}}</label>
              </template>
            </el-table-column>
          </el-table>
          <!--工具条-->
          <el-col :span="24" class="toolbar">
            <el-pagination
              :current-page="hisCurrentPage"
              :page-size="hisPageSize"
              @size-change="handleHisPageSizeChange"
              @current-change="handleHisCurrentPageChange"
              layout="total,sizes,prev, pager, next, jumper"
              :total="hisTotal" style="text-align: center">
            </el-pagination>
          </el-col>
        </el-tab-pane>
      </el-tabs>
      <el-dialog :title="groupSenfPlanDialogTitle" :visible.sync="addSmsVisiable" width="550px">
        <el-form :model="addSmsForm" ref="addSmsForm" style="margin-left: 70px" :rules="rules1">
          <el-form-item label="群发名称" prop="title"
                        >
            <el-input style="width: 300px" v-model="addSmsForm.title" placeholder='请输入群发名称'></el-input>
          </el-form-item>
          <el-form-item label="短信模板" prop="templateAliId"
                        >
            <el-select  v-model="addSmsForm.templateAliId" placeholder="请选择模板类型"
                       @change="getSmsContent" style="width: 300px">
              <el-option
                v-for="item in $store.getters.SMS_TEMPLATE_TYPE"
                :label="item.cnDictValname"
                :key="item.dictVal"
                :value="item.dictVal">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="短信内容">
            <el-input style="width: 300px; " :rows="5" type="textarea" v-model="addSmsForm.templateContent" disabled
                      placeholder="示例：
尊敬的${name},您的订单号为${orderNum}的货物已完成签收，签收人${signNmae}"></el-input>
          </el-form-item>
          <el-form-item label="发送方式"  prop="sendType"
                        >
            <template>
              <el-radio-group v-model="addSmsForm.sendType">
                <el-radio :label="114009001">手动发送</el-radio>
                <el-radio :label="114009002">定时发送</el-radio>
              </el-radio-group>
            </template>
          </el-form-item>
          <el-form-item label="发送时间" v-if="addSmsForm.sendType === 114009002"
                       >
            <template slot-scope="scope">
              <el-date-picker type="datetime" place="请选择时间" v-model="addSmsForm.sendTime"></el-date-picker>
            </template>
          </el-form-item>
          <el-form-item label="发送对象" prop="sendToStmPersonal"   >
            <template>
              <el-radio-group v-model="addSmsForm.sendToStmPersonal">
                <el-radio :disabled="groupSenfPlanDialogTitle === '编辑短信群发'" :label="111002001">系统用户</el-radio>
                <el-radio :disabled="groupSenfPlanDialogTitle === '编辑短信群发'" :label="111002002">非系统用户</el-radio>
              </el-radio-group>
            </template>
          </el-form-item>
          <el-button type="primary" style="margin-left: 130px" @click="addNewGroupSendPlan">保存</el-button>
          <el-button @click="cancleAddSms">取消</el-button>
        </el-form>
      </el-dialog>
      <el-dialog title="群发对象" :visible.sync="acceptPersonsVisiable" size="large">
        <search-bar more-display>
          <el-row :span="24">
            <el-col :span="8">
              <el-form-item label="客户名称" :label-width="formItemWidth">
                <el-input v-model="acceptPersonCondition.realName" placeholder="请输入客户名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="客户手机" :label-width="formItemWidth">
                <el-input v-model="acceptPersonCondition.phone" placeholder="请输入客户手机"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="企业名称" :label-width="formItemWidth">
                <el-input v-model="acceptPersonCondition.enterprise" placeholder="请输入企业名称"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :span="24">
            <el-col :span="8">
              <el-form-item label="注册日期" :label-width="formItemWidth">
                <el-date-picker type="daterange" v-model="acceptPersonCondition.createDate"
                                placeholder="请选择注册日期"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="邀请人" :span="8" :label-width="formItemWidth">
                <el-input v-model="acceptPersonCondition.partnerName" placeholder="请输入邀请人姓名"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="所在城市" :label-width="formItemWidth">
                <address-select
                  style="width: 100%"
                  @getAddresses="getAddresses"
                  v-model="acceptPersonCondition.address"
                  placeholder="请选择所在城市"
                ></address-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :span="24">
            <el-col :span="8">
              <el-form-item label="发货日期" :label-width="formItemWidth">
                <el-date-picker type="daterange" placeholder="请选择日期范围"
                                v-model="acceptPersonCondition.confirmDate"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label-width="30px">
                <template slot-scope="scope">
                  <el-checkbox-group v-model="acceptPersonCondition.haveOrders">
                    <el-checkbox label="111002002">未发货</el-checkbox>
                    <el-checkbox label="111002001">有发货</el-checkbox>
                  </el-checkbox-group>
                </template>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="订单数量" :label-width="formItemWidth">
                <el-select placeholder="请选择订单数量" v-model="acceptPersonCondition.orderNumbers">
                  <el-option
                    v-for="item in $store.getters.ORDER_NUMBERS"
                    :label="item.cnDictValname"
                    :key="item.cnDictValname"
                    :value="item.cnDictValname">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </search-bar>
        <el-button type="primary" v-if="sels.status === 114008001" class="mButton mButtonLeft"
                   @click="acceptPersonFormVisiable2">手动添加
        </el-button>
        <el-button type="primary" class="mButton mButtonRight" @click="resetAcceptPersonForm">重置</el-button>
        <el-button type="primary" class="mButton mButtonRight" @click="searchUsers1"  v-loading="searchAcceptPersons">查询</el-button>
        <el-table :data="userTableData" border>
          <el-table-column type="index" label="序号" min-width="20px"></el-table-column>
          <el-table-column prop="realName" label="客户名称" min-width="150px"></el-table-column>
          <el-table-column prop="phone" label="联系手机" min-width="100px"></el-table-column>
          <el-table-column prop="enterprise" label="企业名称" min-width="170px"></el-table-column>
          <el-table-column prop="createDate" label="注册日期" min-width="100px">
            <template slot-scope="scope">
              <label>{{scope.row.createDate.substring(0,10)}}</label>
            </template>
          </el-table-column>
          <el-table-column prop="partnerName" label="邀请人" min-width="100px"></el-table-column>
          <el-table-column prop="address" label="所在城市" min-width="150px">
            <template slot-scope="scope">
              <label>{{scope.row.province}}{{scope.row.city}}{{scope.row.county}}</label>
            </template>
          </el-table-column>
          <el-table-column>
            <template slot-scope="scope">
              <el-button type="danger" v-if="sels.status === 114008001" @click="deleteMebPerson(scope.row)">删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--工具条-->
        <el-row>
          <el-col :span="24" class="toolbar">
            <el-pagination
              :current-page="userCurrentPage"
              :page-size="userPageSize"
              @size-change="handleUserPageSizeChange"
              @current-change="handleUserCurrentPageChange"
              layout="total,sizes,prev, pager, next, jumper"
              :total="userTotal" style="text-align: center">
            </el-pagination>
          </el-col>
        </el-row>
        <!--<el-row style="padding-top: 5px">-->
          <!--<el-button v-if="sels.status === 114008001" type="primary" class="mButton mButtonRight"-->
                     <!--@click="finalAcceptPersonals">确认-->
          <!--</el-button>-->
          <!--<el-button class="mButton mButtonRight" @click="calcleAddPerson">取消</el-button>-->
        <!--</el-row>-->
      </el-dialog>
      <el-dialog title="新增群发对象" :visible.sync="acceptPersonsVisiable2" size="large">
        <search-bar more-display>
          <el-row :span="24">
            <el-col :span="8">
              <el-form-item label="客户名称" :label-width="formItemWidth">
                <el-input v-model="acceptPersonCondition2.realName" placeholder="请输入客户名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="客户手机" :label-width="formItemWidth">
                <el-input v-model="acceptPersonCondition2.phone" placeholder="请输入客户手机"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="企业名称" :label-width="formItemWidth">
                <el-input v-model="acceptPersonCondition2.enterprise" placeholder="请输入企业名称"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :span="24">
            <el-col :span="8">
              <el-form-item label="注册日期" :label-width="formItemWidth">
                <el-date-picker type="daterange" v-model="acceptPersonCondition2.createDate"
                                placeholder="请选择注册日期"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="邀请人" :span="8" :label-width="formItemWidth">
                <el-input v-model="acceptPersonCondition2.partnerName" placeholder="请输入邀请人姓名"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="所在城市" :label-width="formItemWidth">
                <address-select
                  style="width: 100%"
                  @getAddresses="getAddresses"
                  v-model="acceptPersonCondition2.address"
                  placeholder="请选择所在城市"
                  class="f-w50"></address-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :span="24">
            <el-col :span="8">
              <el-form-item label="发货日期" :label-width="formItemWidth">
                <el-date-picker type="daterange" placeholder="请选择日期范围"
                                v-model="acceptPersonCondition2.confirmDate"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label-width="30px">
                <template slot-scope="scope" >
                  <el-checkbox-group v-model="acceptPersonCondition2.haveOrders">
                    <el-checkbox label="111002002">未发货</el-checkbox>
                    <el-checkbox label="111002001">有发货</el-checkbox>
                  </el-checkbox-group>
                </template>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="订单数量" :label-width="formItemWidth">
                <el-select placeholder="请选择订单数量" v-model="acceptPersonCondition2.orderNumbers">
                  <el-option
                    v-for="item in $store.getters.ORDER_NUMBERS"
                    :label="item.cnDictValname"
                    :key="item.cnDictValname"
                    :value="item.cnDictValname">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </search-bar>
        <el-button type="primary" class="mButton mButtonRight" @click="resetAcceptPersonForm2">重置</el-button>
        <el-button type="primary" class="mButton mButtonRight" @click="searchUsers2" v-loading="searchAcceptPersons2" >查询</el-button>
        <el-table :data="userTableData2" border @selection-change="handlemanualAddPersonalSelectionChange">
          <el-table-column type="selection" min-width="40px"></el-table-column>
          <el-table-column prop="realName" label="客户名称" min-width="100px"></el-table-column>
          <el-table-column prop="phone" label="联系手机" min-width="100px"></el-table-column>
          <el-table-column prop="enterprise" label="企业名称" min-width="150px"></el-table-column>
          <el-table-column prop="createDate" label="注册日期" min-width="150px">
            <template slot-scope="scope">
              <label>{{scope.row.createDate.substring(0,10)}}</label>
            </template>
          </el-table-column>
          <el-table-column prop="partnerName" label="邀请人" min-width="100px"></el-table-column>
          <el-table-column prop="address" label="所在城市" min-width="150px">
            <template slot-scope="scope">
              <label>{{scope.row.province}}{{scope.row.city}}{{scope.row.county}}</label>
            </template>
          </el-table-column>
        </el-table>
        <!--工具条-->
        <el-row>
          <el-col :span="24" class="toolbar">
            <el-pagination
              :current-page="userCurrentPage2"
              :page-size="userPageSize2"
              @size-change="handleUserPageSizeChange2"
              @current-change="handleUserCurrentPageChange2"
              layout="total,sizes,prev, pager, next, jumper"
              :total="userTotal2" style="text-align: center">
            </el-pagination>
          </el-col>
        </el-row>
        <el-row :span="24" style="margin-top: 10px">
          <el-col :span="4">
            <el-checkbox v-model="checked">全选查询结果</el-checkbox>
          </el-col>
          <el-col :span="20">
            <el-button type="primary" class="mButton mButtonRight" @click="manualAddPersonal" v-loading="addLoading">确认</el-button>
            <el-button class="mButton mButtonRight" @click="cancleManualAddPersonal">取消</el-button>
          </el-col>
        </el-row>
      </el-dialog>
      <el-dialog title="发送效果" :visible.sync="testSendSmsDialogViaiable" size="tiny">
        <el-form>
          <el-form-item label="测试发送效果" :rules="{required: true, message: '请输入测试手机号'}">
            <el-input placeholder="请输入发送手机号" style="width: 320px" v-model="testPhoneNumber"></el-input>
            <el-button type="primary" @click="sendTestSendSms">发送</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
      <el-dialog title="导入群发对象" :visible.sync="exportPhonesViaiable">
        <search-bar>
          <el-row :span="24">
            <el-col :span="8">
              <el-form-item label="电话">
                <el-input v-model="searchPhone" placeholder="请输入电话"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </search-bar>
        <el-upload
          v-if="sels.status === 114008001"
          style="display: inline-block;margin-left: 10px"
          show-file-list="false"
          :file-list="fileList"
          :on-success="importPhones"
          :action="'/api/v3.0/admin/api/sms_group_send_plan/import_phones/import?id='+selectedRowId ">
          <el-button  type="primary">导入</el-button>
          <label style="color: orange">（请确认导入的手机号码无重复）</label>
        </el-upload>
        <el-button @click.native="resetSearchPhones" type="primary" class="mButton mButtonRight">重置</el-button>
        <el-button @click.native="searchImportPhones" type="primary" class="mButton mButtonRight">查询</el-button>
        <el-table :data="sendPhones" border >
          <el-table-column type="index" label="序号"></el-table-column>
          <el-table-column  label="手机号码" prop="phone"></el-table-column>
          <el-table-column  label="操作" >
            <template slot-scope="scope">
              <el-button @click.native="deleteMebPerson2(scope.row)" type="danger">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--工具条-->
        <el-row>
        <el-col :span="24" class="toolbar" >
          <el-pagination
            :current-page="currentPage4"
            :page-size="pageSize4"
            @size-change="handlePageSizeChange4"
            @current-change="handleCurrentPageChange4"
            layout="total,sizes,prev, pager, next, jumper"
            :total="total4" style="float: right;">
          </el-pagination>
        </el-col>
        </el-row>
      </el-dialog>
    </div>
  </section>
</template>
<script>
import {
  searchSendSms,
  deletGroupSend,
  groupSendSms,
  changeStatus,
  getSmsTemplet,
  getSmsGroupSendPlan,
  saveNewGroupSendPlan,
  saveAcceptPhones,
  getAcceptPhones,
  // searchAcceptPhonesNoPage,
  testSend,
  getSendPhonesByPlanId,
  deleteAcceptPhones, saveAllPersonalsForSendPlan
} from '../../api/v3/SmsTemplet.js';
import {resetObjNull} from '../../lib/util';
import {searchMebPersonsForSendSmsNew} from '../../api/v3/MebPersonal';
export default {
  data () {
    return {
      formItemWidth: '80px',
      token: this.$store.state.token,
      // 复选框选中数据
      sels: [],
      // 列表数据
      smsTableData: [],
      // 加载状态
      smsListLoading: false,

      // 分页设置
      currentPage: 1,
      pageSize: 10,

      // 用户列表查询条件
      condition: {
        EQ_templateAliId: null,
        createDate: null,
        EQ_status: null,
        EQ_sendType: null,
        LIKE_title: null
      },
      hisCondition: {
        EQ_sendResult: null,
        LIKE_phone: null,
        fixedTime: null
      },
      addSmsForm: {
        title: null,
        templateAliId: null,
        templateContent: null,
        sendType: null,
        sendTime: null,
        sendToStmPersonal: null
      },
      total: 0,
      allSms: 'sendSmsTab',
      addSmsVisiable: false,
      addresses: [],
      // orderNumbers: ['1 - 100', '101 - 200', '201 - 300', '>=301'],
      acceptPersonsVisiable: false,
      acceptPersonsVisiable2: false,
      exportPhonesViaiable: false,
      acceptPersonCondition: {
        realName: null,
        phone: null,
        enterprise: null,
        createDate: null,
        partnerName: null,
        address: null,
        haveOrders: [],
        confirmDate: null,
        orderNumbers: null
      },
      userPageSize: 10,
      userCurrentPage: 1,
      userTotal: 0,
      userPageSize2: 10,
      userCurrentPage2: 1,
      userTotal2: 0,
      currentPage4: 1,
      pageSize4: 10,
      total4: 0,
      hisPageSize: 10,
      hisCurrentPage: 1,
      hisTotal: 0,
      userTableData: [],
      userTableData2: [],
      acceptPersonCondition2: {
        realName: null,
        phone: null,
        enterprise: null,
        createDate: null,
        partnerName: null,
        address: null,
        haveOrders: [],
        confirmDate: null,
        orderNumbers: null
      },
      filtersTool: '',
      filtersTool2: '',
      filtersTool3: '',
      personalIds: '',
      checked: false,
      manuSels: [],
      manualSelsAll: [],
      indecatorLabel: false,
      newFilters: '',
      groupSenfPlanDialogTitle: '',
      selectedRow: null,
      haveSendFilters: null,
      indecatorLabel3: false,
      userTableDataAll: [], // 保存添加客户时，不分页的所有客户
      finalAcceptPersons: [], // 最终添加好的客户，用来发送短信
      testSendSmsDialogViaiable: false,
      testPhoneNumber: '',
      searchAcceptPersons: false,
      searchAcceptPersons2: false,
      addLoading: false,
      hisSendSmsTableData: [],
      sendPhones: [],
      fileList: [],
      searchPhone: '',
      selectedRowId: '',
      rules1: {
        title: [{required: true, message: '请输入群发名称', trigger: 'blur'}],
        templateAliId: [{type: 'number', required: true, message: '短信模板不能为空', trigger: 'blur'}],
        sendType: [{type: 'number', required: true, message: '发送方式不能为空', trigger: 'blur'}],
        sendToStmPersonal: [{type: 'number', required: true, message: '发送对象不能为空', trigger: 'blur'}]
      }
    };
  },
  methods: {
    handlePageSizeChange (val) {
      this.pageSize = val;
      this.searchSMs();
    },
    handleCurrentPageChange (val) {
      this.currentPage = val;
      this.searchSMs();
    },
    handleUserPageSizeChange (val) {
      this.userPageSize = val;
      this.searchUsers1();
    },
    handleUserCurrentPageChange (val) {
      this.userCurrentPage = val;
      this.searchUsers1();
    },
    handleUserPageSizeChange2 (val) {
      this.userPageSize2 = val;
      this.searchUsers2();
    },
    handleUserCurrentPageChange2 (val) {
      this.userCurrentPage2 = val;
      this.searchUsers2();
    },
    handleHisPageSizeChange (val) {
      this.hisPageSize = val;
      this.searchHisSendSms();
    },
    handleHisCurrentPageChange (val) {
      this.hisCurrentPage = val;
      this.searchHisSendSms();
    },
    addSms () {
      this.groupSenfPlanDialogTitle = '新建短信群发';
      this.addSmsVisiable = true;
      resetObjNull(this.addSmsForm);
      this.addSmsForm.templateContent = '';
    },
    addNewGroupSendPlan () {
      this.$refs['addSmsForm'].validate((valid) => {
        if (valid) {
          saveNewGroupSendPlan(this.addSmsForm).then((res) => {
            if (res.data) {
              this.addSmsVisiable = false;
              this.$message.success(this.groupSenfPlanDialogTitle + '成功');
              this.getSmsTableData();
            }
          });
        }
      });
    },
    confirm (val) {
      changeStatus(val.id).then((res) => {
        if (res.data) {
          this.$message.success('审核成功');
          this.getSmsTableData();
        }
      });
    },
    cancleConfirm (val) {
      this.$confirm('确认撤销此群发计划吗?', '提示', {
        type: 'warning'
      }).then(() => {
        changeStatus(val.id).then((res) => {
          if (res.data) {
            this.$message.success('撤销成功');
            this.getSmsTableData();
          }
        });
      });
    },
    groupSendSms (val) {
      this.$confirm('确认执行群发操作?', '提示', {
        type: 'warning'
      }).then(() => {
        groupSendSms(val.id).then((res) => {
          if (res.data) {
            this.$message.success('发送成功');
            this.getSmsTableData();
          }
        });
      });
    },
    testSendSms (val) {
      this.sels = val;
      this.testPhoneNumber = '';
      this.testSendSmsDialogViaiable = true;
    },
    sendTestSendSms () {
      if (this.testPhoneNumber === null || this.testPhoneNumber === '') {
        this.$message.error('电话号码不能为空');
        return;
      }
      this.testSendSmsDialogViaiable = false;
      testSend(this.sels.id, this.testPhoneNumber).then((res) => {
        if (res.data) {
          this.$message.success('发送成功');
        }
      });
    },
    editGroupSendPlan (val) {
      this.groupSenfPlanDialogTitle = '编辑短信群发';
      this.addSmsVisiable = true;
      this.addSmsForm = Object.assign({}, val);
      this.addSmsForm.templateAliId = Number(val.templateAliId);
    },
    deleteGroupSendPlan (val) {
      this.$confirm('确认删除该群发短信吗?', '提示', {
        type: 'warning'
      }).then(() => {
        deletGroupSend(val.id).then((res) => {
          this.$message.success('删除成功');
          this.getSmsTableData();
        });
      });
    },
    acceptPersonFormVisiable (val) {
      this.sels = val;
      this.userCurrentPage = 1;
      this.acceptPersonsVisiable = true;
      this.resetAcceptPersonForm();
      this.filtersTool = '';
      this.selectedRow = val;
      this.getAcceptPhones(val.id, '');
    },
    acceptPersonFormVisiable2 () {
      this.acceptPersonsVisiable2 = true;
      this.resetAcceptPersonForm2();
      this.getUsers2('');
      this.filtersTool2 = '';
      this.checked = false;
      this.manuSels = [];
    },
    // 获列表
    getSmsTableData (filter = '') {
      this.smsListLoading = true;
      getSmsGroupSendPlan({
        filters: filter,
        sort: 'createDate,desc',
        page: this.currentPage - 1,
        size: this.pageSize
      }).then((res) => {
        if (res.data) {
          this.smsListLoading = false;
          this.smsTableData = res.data;
          this.total = Number(res.headers['x-total-count']);
        }
      });
    },
    // 根据查询条件获取短信
    searchSMs () {
      let filters = '';
      for (let p in this.condition) {
        if (this.condition[p] !== null && this.condition[p] !== undefined && this.condition[p] !== null) {
          if (this.condition[p] instanceof Array) {
            if (this.condition[p].length !== 0) {
              filters += 'GT_' + p + '=' + this.condition[p][0].Format('yyyy-MM-dd') + ' 00:00:00;LT_' + p + '=' + this.condition[p][1].Format('yyyy-MM-dd') + ' 23:59:59;';
            }
          } else {
            filters += p + '=' + this.condition[p] + ';';
          }
        }
      }
      this.getSmsTableData(filters);
    },
    searchHisSendSms () {
      let filters = '';
      for (let p in this.hisCondition) {
        if (this.hisCondition[p] !== null && this.hisCondition[p] !== undefined && this.hisCondition[p] !== null) {
          if (this.hisCondition[p] instanceof Array) {
            if (this.hisCondition[p].length !== 0) {
              filters += 'GT_' + p + '=' + this.hisCondition[p][0].Format('yyyy-MM-dd') + ' 00:00:00;LT_' + p + '=' + this.hisCondition[p][1].Format('yyyy-MM-dd') + ' 23:59:59;';
            }
          } else {
            filters += p + '=' + this.hisCondition[p] + ';';
          }
        }
      }
      this.haveSendFilters = filters;
      searchSendSms({
        filters: filters,
        page: this.hisCurrentPage - 1,
        sort: 'createdDate,desc',
        size: this.hisPageSize
      }).then((res) => {
        if (res.data) {
          this.hisSendSmsTableData = res.data;
          this.hisTotal = Number(res.headers['x-total-count']);
        }
      });
    },
    exportSendSms () {
      location.href = '/api/v3.0/admin/api/sms_send/download?filters=' + this.haveSendFilters;
    },
    // 用戶列表选择改变事件
    smsTableSelsChange (sels) {
      this.sels = sels;
    },
    getAddresses (data) {
      this.addresses = data;
    },
    resetAcceptPersonForm () {
      resetObjNull(this.acceptPersonCondition);
      this.filtersTool = '';
    },
    resetAcceptPersonForm2 () {
      resetObjNull(this.acceptPersonCondition2);
      this.filtersTool2 = '';
    },
    searchUsers () {
      this.filtersTool = '';
      for (let o in this.acceptPersonCondition) {
        if (this.acceptPersonCondition[o] === null || this.acceptPersonCondition[o] === undefined || this.acceptPersonCondition[o] === '') {
          continue;
        } else {
          if (o.indexOf('dress') > 0) {
            if (this.acceptPersonCondition[o].length === 1) {
              this.filtersTool += 'EQ_provinceId=' + this.acceptPersonCondition[o][0] + ';';
            } else if (this.acceptPersonCondition[o].length === 2) {
              this.filtersTool += 'EQ_provinceId=' + this.acceptPersonCondition[o][0] + ';EQ_cityId=' + this.acceptPersonCondition[o][1] + ';';
            } else if (this.acceptPersonCondition[o].length === 3) {
              this.filtersTool += 'EQ_provinceId=' + this.acceptPersonCondition[o][0] + ';EQ_cityId=' + this.acceptPersonCondition[o][1] + ';EQ_countyId=' + this.acceptPersonCondition[o][2];
            }
          } else if (o.indexOf('Date') > 0) {
            if (this.acceptPersonCondition[o].length > 0) {
              this.filtersTool += 'GT_' + o + '=' + this.acceptPersonCondition[o][0].Format('yyyy-MM-dd') + ' 00:00:00;LT_' + o + '=' + this.acceptPersonCondition[o][1].Format('yyyy-MM-dd') + ' 23:59:59;';
            }
          } else if (o.indexOf('veOrders') > 0) {
            if (this.acceptPersonCondition[o].length === 1) {
              this.filtersTool += o + '=' + this.acceptPersonCondition[o][0] + ';';
            }
            if (this.acceptPersonCondition[o].length === 2) {
              this.$message.error('有无发货只能选一项');
            }
          } else {
            this.filtersTool += 'LIKE_' + o + '=' + this.acceptPersonCondition[o] + ';';
          }
        }
      }
    },
    searchUsersFilters2 () {
      this.filtersTool2 = '';
      for (let o in this.acceptPersonCondition2) {
        if (this.acceptPersonCondition2[o] === null || this.acceptPersonCondition2[o] === undefined || this.acceptPersonCondition2[o] === '') {
          continue;
        } else {
          if (o.indexOf('dress') > 0) {
            if (this.acceptPersonCondition2[o].length === 1) {
              this.filtersTool2 += 'EQ_provinceId=' + this.acceptPersonCondition2[o][0] + ';';
            } else if (this.acceptPersonCondition2[o].length === 2) {
              this.filtersTool2 += 'EQ_provinceId=' + this.acceptPersonCondition2[o][0] + ';EQ_cityId=' + this.acceptPersonCondition2[o][1] + ';';
            } else if (this.acceptPersonCondition2[o].length === 3) {
              this.filtersTool2 += 'EQ_provinceId=' + this.acceptPersonCondition2[o][0] + ';EQ_cityId=' + this.acceptPersonCondition2[o][1] + ';EQ_countyId=' + this.acceptPersonCondition2[o][2];
            }
          } else if (o.indexOf('Date') > 0) {
            if (this.acceptPersonCondition2[o].length > 0) {
              this.filtersTool2 += 'GT_' + o + '=' + this.acceptPersonCondition2[o][0].Format('yyyy-MM-dd') + ' 00:00:00;LT_' + o + '=' + this.acceptPersonCondition2[o][1].Format('yyyy-MM-dd') + ' 23:59:59;';
            }
          } else if (o.indexOf('veOrders') > 0) {
            if (this.acceptPersonCondition2[o].length === 1) {
              this.filtersTool2 += o + '=' + this.acceptPersonCondition2[o][0] + ';';
            }
            if (this.acceptPersonCondition2[o].length === 2) {
              this.$message.error('有无发货只能选一项');
            }
          } else {
            this.filtersTool2 += 'LIKE_' + o + '=' + this.acceptPersonCondition2[o] + ';';
          }
        }
      }
    },
    searchUsers1 () {
      this.searchUsers();
      this.getAcceptPhones(this.selectedRow.id, this.filtersTool);
    },
    searchUsers2 () {
      this.searchUsersFilters2();
      this.getUsers2(this.filtersTool2);
    },
    getUsers2 (filters) {
      this.searchAcceptPersons2 = true;
      searchMebPersonsForSendSmsNew({
        filters: filters,
        sorts: '',
        size: this.userPageSize2,
        page: this.userCurrentPage2 - 1
      }).then(res => {
        if (res.data) {
          this.searchAcceptPersons2 = false;
          this.userTableData2 = res.data;
          this.userTotal2 = Number(res.headers['x-total-count']);
        }
      });
    },
    deleteMebPerson (val) {
      this.$confirm('确认删除该接受对象？', '提示', {type: 'warning'}).then(() => {
        deleteAcceptPhones({groupSendId: this.selectedRow.id, phones: val.phone}).then((res) => {
          if (res.data) {
            this.searchUsers1();
          }
        });
      });
    },
    cancleManualAddPersonal () {
      this.acceptPersonsVisiable2 = false;
    },
    handlemanualAddPersonalSelectionChange (val) {
      this.manuSels = val;
    },
    manualAddPersonal () {
      this.addLoading = true;
      let self = this;
      let phones = '';

      if (this.checked) {
        saveAllPersonalsForSendPlan(this.filtersTool2, this.selectedRow.id).then((res) => {
          if (res.data) {
            this.addLoading = false;
            this.getAcceptPhones(this.selectedRow.id, '');
            this.resetAcceptPersonForm();
            self.acceptPersonsVisiable2 = false;
          }
        });
      } else {
        if (self.manuSels === null || self.manuSels === [] || self.manuSels === undefined || self.manuSels.length === 0) {
          this.$message.error('请至少选择一条记录');
          this.addLoading = false;
          return;
        }
        if (self.manuSels !== null && self.manuSels !== [] && self.manuSels !== undefined && self.manuSels.length !== 0) {
          for (let p in self.manuSels) {
            if (p !== 'contains') {
              phones += self.manuSels[p].phone + ',';
            }
          }
          saveAcceptPhones(this.selectedRow.id, phones).then((res) => {
            if (res.data) {
              this.addLoading = false;
              this.getAcceptPhones(this.selectedRow.id, '');
              this.resetAcceptPersonForm();
              self.acceptPersonsVisiable2 = false;
            }
          });
        }
      }
    },
    getSmsContent () {
      getSmsTemplet({id: this.addSmsForm.templateAliId}).then((res) => {
        if (res.data) {
          let temp = res.data;
          this.addSmsForm.templateContent = temp.content;
        }
      });
    },
    getAcceptPhones (id, filters) {
      this.searchAcceptPersons = true;
      getAcceptPhones({
        id: id,
        filters: filters,
        page: this.userCurrentPage - 1,
        size: this.userPageSize
      }).then((res) => {
        if (res.data) {
          this.searchAcceptPersons = false;
          this.userTableData = res.data;
          this.userTotal = Number(res.headers['x-total-count']);
        }
      });
    },
    importAcceptPhones (val) {
      this.exportPhonesViaiable = true;
      this.searchPhone = '';
      this.sels = val;
      this.selectedRow = val;
      this.selectedRowId = val.id;
      this.getSendPhones('');
    },
    importPhones (response) {
      this.fileList = [];
      if (response) {
        this.getSendPhones('');
        this.$message.success('导入成功');
      }
    },
    getSendPhones (filters) {
      getSendPhonesByPlanId({
        id: this.selectedRowId,
        filters: filters,
        page: this.currentPage4 - 1,
        size: this.pageSize4
      }).then(res => {
        if (res.data) {
          this.sendPhones = res.data;
          this.total4 = Number(res.headers['x-total-count']);
        }
      });
    },
    searchImportPhones () {
      let filter = this.searchPhone;
      this.getSendPhones(filter);
    },
    resetSearchPhones () {
      this.searchPhone = '';
    },
    deleteMebPerson2 (val) {
      this.$confirm('确认删除该接受对象？', '提示', {type: 'warning'}).then(() => {
        deleteAcceptPhones({groupSendId: this.selectedRow.id, phones: val.phone}).then((res) => {
          this.getSendPhones(this.searchPhone);
        });
      });
    },
    handlePageSizeChange4 (val) {
      this.pageSize4 = val;
      this.getSendPhones(this.searchPhone);
    },
    handleCurrentPageChange4 (val) {
      this.currentPage4 = val;
      this.getSendPhones(this.searchPhone);
    },
    cancleAddSms () {
      resetObjNull(this.addSmsForm);
      this.addSmsForm.templateContent = '';
      this.addSmsVisiable = false;
    },
    // 重置查询条件
    resetCondition () {
      resetObjNull(this.condition);
      this.getSmsTableData();
    },
    resetHisCondition () {
      resetObjNull(this.hisCondition);
      this.haveSendFilters = '';
      this.searchHisSendSms();
    }
  },
  mounted () {
    this.getSmsTableData();
    this.searchHisSendSms();
    this.$store.commit('initDict');
  }
};
</script>
